#pragma once
#include "meshloader.h"
#include "MS3D.h"
#include "FileDataStream.h"

namespace DreamEngine
{

class _EngineExport CMS3DMeshLoader : public CMeshLoader
{
public:
	CMS3DMeshLoader(CRenderSystem* pRenderSystem);
	~CMS3DMeshLoader(void);

	virtual bool LoadFromFile(const std::string& name,  CMesh* pMesh);

protected:

	void		StartLoad(const std::string& fileName);
	void		EndLoad();

	bool		ReadHeader(void);
	void		ReadVertex(void);
	void		ReadFace(void);
	void		ReadGroup(void);
	void		ReadMaterial(void);
	void		ReadAnimationInfo(void);
	void		ReadBones(void);
	
	void		ParseToMesh(CMesh* pMesh);

protected:

	void		_CreateMeshVertex(CMesh* pMesh);
	void		_CreateBone(CMesh* pMesh);

	CFileDataStream m_meshFile;

	MS3DVertex*		m_pVertexs;
	m_uint16		m_vertexNum;

	MS3DFace*		m_pFaces;
	m_uint16		m_faceNum;

	MS3DGroup*		m_pGroups;
	m_uint16		m_groupNum;

	MS3DMaterial*	m_pMaterials;
	m_uint16		m_materialNum;

	float			m_animationFPS;
	float			m_currentTime;
	m_uint32		m_totalFrames;

	MS3DBone*		m_pBones;
	m_uint16		m_boneNum;

//	MS3DMeshVertex* m_pMeshVertex;
};

}

